
let Api = {
    
}
let url = 'https://novel.wangchunjian.top/novel/'

function queryString(params){
    let str = ''
    let index=0
    for(let key  in params){
    if(index)
        str+='&'+key+'='+params[key]
    else
        str+='?'+key+'='+params[key]
    index++
    }
    return str
}

Api.searchNovel =  (params)=>{
    return new Promise((resolve, reject) => {
        fetch(url+'search'+queryString(params)).then((res) => resolve(res.json()))
            .catch((error) => { reject(error) })
    })
}

Api.detailNovel =  (params)=>{
    return new Promise((resolve, reject) => {
        fetch(url+'detail'+queryString(params)).then((res) => resolve(res.json()))
            .catch((error) => { reject(error) })
    })
}

Api.articleNovel =  (params)=>{
    return new Promise((resolve, reject) => {
        fetch(url+'index'+queryString(params)).then((res) => resolve(res.json()))
            .catch((error) => { reject(error) })
    })
}

Api.categoryNovel =  (params)=>{
    return new Promise((resolve, reject) => {
        fetch(url+'category'+queryString(params)).then((res) => resolve(res.json()))
            .catch((error) => { reject(error) })
    })
}

Api.indexNovel =  ()=>{
    return new Promise((resolve, reject) => {
        fetch(url+'home').then((res) => resolve(res.json()))
            .catch((error) => { reject(error) })
    })
}

export default Api
